Skip to content

Conversation

panchenko
Copy link
Contributor

It someone wants it nullable, that should be defined via the type parameter, e.g. StatusOr<@Nullable Foo> foo

@ejona86
Copy link
Member

ejona86 commented Sep 18, 2025

I'm a little bit worried that this is getting into specifics of one Nullable annotation vs another; I know they aren't all equivalent and there were limitations lifted with later annotations. Given that everything is @Nullable, we know this annotation has no behavior right now, which means verifying behavior is out of the question.

@panchenko
Copy link
Contributor Author

I was trying to use this type in our code, with the result of unexpected warnings from IDE

There are plenty of such warnings in this repo as well, e.g.

ClusterResolutionResult result = statusOrResult.getValue();
List<EquivalentAddressGroup> addresses = result.addresses;

getValue() is nullable, so result can be null, and then there is a warning for result.addresses

@ejona86
Copy link
Member

ejona86 commented Sep 18, 2025

All arguments/return types in gRPC should be Nullable from a tool's perspective. We don't have NonNull enabled at the package level. To my current understanding, if these changes here are causing changes in the IDE, then the IDE is broken.

@panchenko
Copy link
Contributor Author

From a tool's perspective - default nullability is unknown.
However ,getValue() is explicitly annotated as @Nullable, that makes the result local variable also nullable. There are no null checks in this code, so the tool issues a warning about possible NPE. That's the whole point of using @Nullable. The tool (IDE) works correctly.

Why getValue() is @Nullable?

@ejona86
Copy link
Member

ejona86 commented Sep 19, 2025

The suggested approach doesn't actually work with javax.annotation.Nullable:

   grpc-java/api/src/main/java/io/grpc/StatusOr.java:69: error: annotation @Nullable not applicable in this type context
    private static final StatusOr<@Nullable Object> TESTING = null;

But the @Nullable isn't actually providing any value (as it doesn't actually restrict whether the method can return null, as no method is annotated non-null), so if it is causing problem we can remove it for now.

@panchenko
Copy link
Contributor Author

The suggested approach doesn't actually work with javax.annotation.Nullable

Correct, should be newer annotations, e.g. jspecify.

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Sep 23, 2025
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Sep 23, 2025
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning is a bit different, but it is best to remove this at present.

@ejona86 ejona86 merged commit b33c17f into grpc:master Sep 30, 2025
15 of 17 checks passed
ejona86 pushed a commit to ejona86/grpc-java that referenced this pull request Sep 30, 2025
It someone wants it nullable, that should be defined via the type
parameter, e.g. `StatusOr<@nullable Foo> foo`
@ejona86 ejona86 added the TODO:backport PR needs to be backported. Removed after backport complete label Oct 1, 2025
ejona86 pushed a commit that referenced this pull request Oct 1, 2025
It someone wants it nullable, that should be defined via the type
parameter, e.g. `StatusOr<@nullable Foo> foo`
@AgraVator AgraVator removed the TODO:backport PR needs to be backported. Removed after backport complete label Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants